//
//  ShipVo.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-6-29.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//
//  存储船的数据模型

#import "ShipVo.h"

@implementation ShipVo

@synthesize shipId = _shipId;
@synthesize shipName = _shipName;

@synthesize attackSystemIds = _attackSystemIds;
@synthesize defenseSystemIds = _defenseSystemIds;
@synthesize servoSystemIds = _servoSystemIds;
@synthesize airplaneIds = _airplaneIds;

+(id) shipVoWithId:(int)shipId
{
    return [[[ShipVo alloc] initVoWithId:shipId] autorelease];
}

-(id) initVoWithId:(int)shipId
{
    // always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init])) 
    {
        self.shipId = shipId;
        self.shipName = @"aaa";
        self.attackSystemIds    = [NSMutableDictionary dictionaryWithCapacity:8];
        self.defenseSystemIds   = [NSMutableDictionary dictionaryWithCapacity:8];
        self.servoSystemIds     = [NSMutableDictionary dictionaryWithCapacity:8];
        self.airplaneIds        = [NSMutableDictionary dictionaryWithCapacity:8];
    }
    
    return self;
}

- (id) initWithCoder: (NSCoder *)coder  
{  
    if (self = [super init])  
    {  
        self.shipId  = [coder decodeIntForKey:@"level"]; 
        self.shipName    = [coder decodeObjectForKey:@"shipName"]; 
        self.attackSystemIds  = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:[coder decodeObjectForKey:@"attackSystemIds"]]; 
        self.defenseSystemIds  = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:[coder decodeObjectForKey:@"defenseSystemIds"]]; 
        self.servoSystemIds  = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:[coder decodeObjectForKey:@"servoSystemIds"]]; 
        self.airplaneIds  = (NSMutableDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:[coder decodeObjectForKey:@"airplaneIds"]]; 
        
    }  
    return self;  
}  

- (void) encodeWithCoder: (NSCoder *)coder  
{  
    [coder encodeInt:self.shipId forKey:@"level"]; 
    [coder encodeObject:self.shipName forKey:@"shipName"]; 
    
    [coder encodeObject:[NSKeyedArchiver archivedDataWithRootObject:self.attackSystemIds] forKey:@"attackSystemIds"]; 
    [coder encodeObject:[NSKeyedArchiver archivedDataWithRootObject:self.defenseSystemIds] forKey:@"defenseSystemIds"]; 
    [coder encodeObject:[NSKeyedArchiver archivedDataWithRootObject:self.servoSystemIds] forKey:@"servoSystemIds"]; 
    [coder encodeObject:[NSKeyedArchiver archivedDataWithRootObject:self.airplaneIds] forKey:@"airplaneIds"]; 
} 

- (void)dealloc
{
    if(_shipName)
    {
        [_shipName release];
        _shipName = nil;
    }
    
    if(_attackSystemIds)
    {
        [_attackSystemIds removeAllObjects];
        [_attackSystemIds release];
        _attackSystemIds = nil;
    }
    
    if(_defenseSystemIds)
    {
        [_defenseSystemIds removeAllObjects];
        [_defenseSystemIds release];
        _defenseSystemIds = nil;
    }
    
    if(_servoSystemIds)
    {
        [_servoSystemIds removeAllObjects];
        [_servoSystemIds release];
        _servoSystemIds = nil;
    }
    
    if(_airplaneIds)
    {
        [_airplaneIds removeAllObjects];
        [_airplaneIds release];
        _airplaneIds = nil;
    }
    
    [super dealloc];
}

@end
